﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Lidgren.Network;

using CodeGame.Networking.Serverside;

namespace CodeGame.ServerObjects
{
    class Player
    {
        private static char[] PasswordCharactors = "0123456789ABCDEF".ToCharArray();

        public string AuthToken;
        public string Nickname;
        public long Resouces = 0;
        public NetConnection Connection;

        public Player(string nick, NetConnection conn)
        {
            this.AuthToken = this.GenerateToken();
            this.Nickname = nick;
            this.Connection = conn;
        }

        public bool WithdrawResouces(int amount)
        {
            if (this.Resouces < amount)
            {
                ServerProtocolChat.SendPrivateChat("", "Not Enough Resources to Complete Action", this.Connection);
                return false;
            }
            this.Resouces -= amount;
            return true;
        }

        private string GenerateToken()
        {
            string str = "";
            for (int i = 0; i < 6; i++)
            {
                str += PasswordCharactors[ServerSingletons.Rand.Next(PasswordCharactors.Length)];
            }
            return str;
        }

        public void GiveResouces(int amount)
        {
            this.Resouces += amount;
        }

        public void SendResouceAlert()
        {
            ServerProtocolChat.SendPrivateChat("", "Resources: " + this.Resouces, this.Connection);
        }
    }
}
